<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title><spring:message code="message.lable.select"/><spring:message code="message.listForm.baoZhuangDanWei"/></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp" %>  
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                 <div class="input">
                	<div class="textalign1"><spring:message code="message.listForm.baoZhuangDanWeiMingCheng"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput" id="searchUnitName" placeholder="<spring:message code="message.listForm.baoZhuangDanWeiMingCheng"/>" maxlength="50" />
                    	</div>
                    
                    <div class="textalign"><spring:message code="message.listForm.baoZhuangDanWeiBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput" id="searchUnitCode" placeholder="<spring:message code="message.listForm.baoZhuangDanWeiBianMa"/>" maxlength="10" />
                    	</div>
                    <div class="textalign" >
                    <button type="button" class="btn btn-success btn-sm" onclick="search();" id="selectDrug"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <button type="button" id="confirm"  onclick="confirm();" class="btn btn-default btn-sm"><spring:message code="message.button.okSpacing"/></button>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
            
    //绑定回车
    $('#searchUnitCode,#searchUnitName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectDrug').click();
        }
    }); 
  
    $("#searchUnitName").focus();//加载页面光标在第一个查询框内
    
    
            function search(page) {
                var code = $.trim($("#searchUnitCode").val());
                var name = $.trim($("#searchUnitName").val());
                $("#gridlist").jqGrid('setGridParam',{  
                    datatype:'json',
                    postData:{"unitCode":code, "unitName":name},
                    page : (page || 1)
                }).trigger("reloadGrid"); //重新载入  
            }
        
            $(function () {
                
                $("#gridlist").jqGrid({
                    url: "${ctx}/stdProdDrugInfo/getSelectUnit.html",
                    mtype: "POST",
                    datatype: "json",
                    autowidth: true,
                    height: 270,
                    colNames: [ 
                                'unitId',
                                '<spring:message code="message.listForm.baoZhuangDanWeiBianMa"/>',
                                '<spring:message code="message.listForm.baoZhuangDanWeiMingCheng"/>'
                                ],
                    colModel: [
                        { name: 'unitId', hidden:true, width: 10, align:"center", sortable: false},
                        { name: 'unitCode', width: 10, align:"center", sortable: false},
                        { name: 'unitName', width: 10, align:"center", sortable: false }
                    ],
                    rowNum: 20,
                    rowList: [10, 20, 50,100],
                    rownumbers: true,
                    pager: "#gridpage",
                    viewrecords: true,
                    caption: "<spring:message code="message.list.packunitDiclist"/>",
                  //序号宽度自动变化
                    gridComplete:function(){
                        //序号列宽度自适应（参数为jqgridID）
                        autoRNWidth("gridlist");
                        //数据只有一条时默认选中（参数为jqgridID）
                        selectByOneData("gridlist");
                    },
                    jsonReader: {
                        id: "unitCode"
                    },
                  /*   gridComplete:function(){        
                        var page = $("#gridlist").jqGrid('getGridParam','page');
                        var rows = $('#gridlist').getGridParam("rowNum");
                        var maxnum = (rows*page).toString();
                        var len = (maxnum.length)*10;
                        $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                        $('#gridlist_rn').css('width',len+'px');
                        
                        selectByOneData("gridlist");
                    } */
                });
                
                $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
                $(window).trigger("resize");
              
            });
            
          //确认
            function confirm() {
                var rowId = $("#gridlist").jqGrid("getGridParam", "selrow") || [];
                 if(rowId.length <=0){
                    $.HN.message.alert("<spring:message code="message.lable.pleaseSelectOperational"/><spring:message code="message.listForm.baoZhuangDanWei"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
                    return;
                 }
                 var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                 var dialog = top.dialog.get(window);
                 var params = {
                    "unitId" : rowdata.unitId,
                    "unitCode" : rowdata.unitCode,
                    "unitName" : rowdata.unitName,
                    "unitStatus" : 1
                 };
                 dialog.close(params);   // 关闭（隐藏）对话框
                 dialog.remove();        // 主动销毁对话框
            }
           
    </script>
</body>
</html>
